﻿using CodeGenerate.Model;
using ShareCode.Util.Helper;
using SqlSugar;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CodeGenerate
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        string connstr;
        ViewModel viewModel;
        public MainWindow()
        {
            InitializeComponent();
            Init();
        }


        private void Init()
        {
            connstr = "server=127.0.0.1;database=estimate;uid=root;pwd=123456;charset=utf8;Allow Zero Datetime=True;Convert Zero Datetime=True";
            viewModel = new ViewModel(connstr)
            {
                ShareEntityPath = "D:\\dotnet\\work\\appraise\\appraise",
                ServerEntityPath = "D:\\dotnet\\work\\appraise\\appraise",
                ServerDaoPath = "D:\\dotnet\\work\\appraise\\appraise",
                ServerBllPath = "D:\\dotnet\\work\\appraise\\appraise",
                ServerControllerPath = "D:\\dotnet\\work\\appraise\\appraise",
                ClientDaoPath = "D:\\dotnet\\work\\appraise\\appraise",

                ShareEntityNamespace = "ShareCode\\Entity",
                ServerEntityNamespace = "Infrastructure\\Entity",
                ServerDaoNamespace = "Dao",
                ServerBllNamespace = "Bll",
                ServerControllerNamespace = "ApiApp\\Controllers",
                ClientDaoNamespace = "ClientDao"
            };

            var mydb = viewModel.GetDb();

            var tables = mydb.DbMaintenance.GetTableInfoList(false);

            Dictionary<string, object> mappings = new Dictionary<string, object>();
            foreach (var table in tables)
            {
                mappings.Add(table.Name, table);
            }
            this.cbbTables.ItemsSource = mappings;


            this.cbbPClass.ItemsSource = EnumHelper.GetAllItems<PEnum>();
            this.cbbPClass.SelectedValue = "Value";
            this.cbbPClass.DisplayMemberPath = "Name";

        }


        //重新生成
        private void Button_Click(object sender, RoutedEventArgs e)
        {

            viewModel.SonPath = this.txtSonPath.Text;
            viewModel.PClass = PEnum.ContainDate;

            viewModel.Gen("user_account");


            var asdfasfd = 2;

        }

        //修改生成
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {

        }
    }
}